package com.dailyblue.java.project.smbms.goods.controller;

import com.dailyblue.java.commons.util.JsonResult;
import com.dailyblue.java.project.smbms.goods.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/goods")
@CrossOrigin
@Slf4j
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    // goods/1
    @GetMapping("/{page}")
    public JsonResult find(@PathVariable("page") int page) {
        log.info("开始商品分页查询");
        return goodsService.findGoods(page);
    }

    // goods/1
    @GetMapping("/{goodsName}/{proId}")
    public JsonResult find(@PathVariable("goodsName") String goodsName,@PathVariable("proId") int proId) {
        log.info("开始商品检索，获取的参数是：{},{}",goodsName,proId);
        return goodsService.find(goodsName.trim(), proId);
    }
    @GetMapping("/1/2/{id}")
    public JsonResult id(@PathVariable("id") int id){
        return goodsService.find(id);
    }
}
